<template>
    <vue-ueditor-wrap :config="myConfig"  v-model="content"></vue-ueditor-wrap>
</template>

<script>
    import VueUeditorWrap from "vue-ueditor-wrap";
    import { getHeaders } from "@/assets/js/common";
    export default {
        name: "EditorText",
        props: {
            value: {  // v-model 的值
                type: String,
                default: ''
            },
            height: {  // v-model 的值
                type: Number,
                default: 400
            },
        },
        watch: {
            value: {
                handler() { // 监听value给content赋值
                    this.content = this.value;
                },
                immediate: true
            },
            content() { // 监听content给value赋值,实现双向绑定
                this.$emit('input', this.content)
            }
        },
        data() {
            return {
                content:"", // 富文本内容
                base: {},
                headers: {},
                credentials: true,
                fileUpload: "",
                myConfig: {
                    toolbars: [[
                        'fullscreen', 'source', '|', 'undo', 'redo', '|', 'fontsize', '|',
                        'bold', 'italic', 'underline', 'fontborder', 'strikethrough',
                        'superscript', 'subscript', 'removeformat', 'formatmatch',
                        'autotypeset', 'blockquote', '|', 'forecolor',
                        'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|',
                        '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
                        'insertimage', 'emotion', 'scrawl',
                        '|', 'inserttable',
                    ]],
                    // 如果需要上传功能,找后端小伙伴要服务器接口地址
                    serverUrl: "",
                    // 你的UEditor资源存放的路径,相对于打包后的index.html
                    UEDITOR_HOME_URL: "./static/UEditor/",
                    // 编辑器不自动被内容撑高
                    autoHeightEnabled: false,
                    // 初始容器高度
                    initialFrameHeight: 440,
                    // 初始容器宽度
                    initialFrameWidth: "100%",
                    // 关闭自动保存
                    enableAutoSave: false,
                    zIndex: 99999
                },
            }
        },
        mounted() {
            this.base = JSON.parse(sessionStorage.base);
            this.fileUpload = this.base.domain_name + "/api/file/upload";
            this.myConfig.serverUrl = this.base.domain_name + "/admin/ueditor/output";
            this.headers = getHeaders(localStorage._token);
        },
        components: {
            VueUeditorWrap
        },

    }
</script>

<style scoped>

</style>